import numpy as np

from mainmethod import *

if __name__ == '__main__':
    flag = 0
    ecfinal = 50000
    k =5
    Img = Load_img('test', flag)
    img = Img[0]
    imgs = copy.deepcopy(img)
    file_name = 'yuanimg.mat'
    scio.savemat(file_name, {'img': imgs})
    # danci_img, lcm, halfsize, data = Over_flow(imgs, flag)
    # # 数组长度
    # data_length = len(data)
    # 获取图片的坐标的长宽
    row, col = imgs.shape
    # 初始图像数据,获取误差以及按照图像的复杂度进行分类
    label, em = get_feature(imgs, flag, 13)
    label, check = cal_entropy(imgs, label, 5, flag)
    Hs = make_hs(label, k, em, flag, check)
    his1,his2,his3 =make_hs2(label, k, imgs, flag, check)
    plt_make3(his1,'His1')
    plt_make3(his2,'His2')
    plt_make3(his3,'His3')
    # His = Hs[1:-1]
    print('总和',  np.sum(Hs,axis=1))
    imgs,ec1,dist1,singleec1,singledist1  = Find_Insert(Hs,imgs,ecfinal,label,check,flag)
    imghs = img_hs(imgs)

    imghs2 = img_hs(img)
    hist1 = hist_make(imgs)
    hist2 = hist_make(img)
    print(np.sum(imghs))
    print(np.sum(imghs2))
    # ecnumber = np.sum(imghs) -np.sum(imghs2)
    # plt_make2(imghs)
    plt_make2(hist2)
    plt_make2(hist1)
    flag = 1
    k =5
    img2 = imgs.copy()
    label, em = get_feature(img2, flag, 13)
    label, check = cal_entropy(img2, label, 5, flag)

    Hs = make_hs(label, k, img2, flag, check)
    print('总和', np.sum(Hs, axis=1))
    # His = Hs[1:-1]
    img2,ec2,dist2,singleec2,singledist2  = Find_Insert(Hs, img2, ecfinal, label, check, flag)
    imghs = img_hs(img2)
    imghs2 = img_hs(img)
    his1, his2, his3 = make_hs2(label, k, img2, flag, check)
    plt_make3(his1,'His1')
    plt_make3(his2,'His2')
    plt_make3(his3,'His3')
    file_name = 'label.mat'
    scio.savemat(file_name, {'label': label})
    file_name = 'imgs.mat'
    scio.savemat(file_name, {'img': img2})
    hist1 = hist_make(img2)
    hist2 = hist_make(img)
    print(np.sum(imghs))
    print(np.sum(imghs2))
    # ecnumber = np.sum(imghs) -np.sum(imghs2)
    # plt_make2(imghs)
    plt_make2(hist2)
    plt_make2(hist1)
    cv2.imwrite('./out11.bmp', imgs)


